﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using ThreeByte.ActiveDeck.Service;
using ThreeByte.ActiveDeck.Data.UserResponse;
using System.IO;
using ThreeByte.Media;
using System.Windows.Threading;
using System.Windows;
using ThreeByte.ActiveDeck.Config;
using log4net;

namespace ThreeByte.ActiveDeck.AddIn.Content.UserResponse
{
    public class TextUpdater : UserResponseFeedbackUpdater
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(TextUpdater));

        private PowerPoint.TextFrame MyTextFrame;

        private QuestionConfig QuestionConfig;
        private ShortAnswerUserData UserData;

        public TextUpdater(string presentation, PowerPoint.Shape shape, WebServiceClient client, QuestionConfig questionConfig)
            : base(presentation, shape, client) {

            MyTextFrame = shape.TextFrame;

            QuestionConfig = questionConfig;
            UserData = questionConfig.InitUserData();

        }

        protected override bool UpdateUserData(System.Xml.Linq.XElement userData) {
            AggregateUserData newUserData = AggregateUserData.ParseXml(userData);
            return UserData.UpdateUserData(newUserData);
        }

        protected override void UpdateGraphic() {
            log.Debug("Updating user text");
            MyTextFrame.TextRange.Text = UserData.TopAnswer;
        }

    }
}
